package enlace.rnf.controlinstancias;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import java.awt.event.ActionListener;
import principal.AutoKit.AutoKit;
import principal.model.vos.Usuarios;
import principal.view.VistaConsolaVenAdmin;
import principal.view.gui.altaComponente.*;
import principal.view.gui.*;

public class ProxyAuthentication extends JFrame{
	private int numUsu= 0;
	public static int x=0;
	public int getNumUsu() {
		return numUsu;
	}

	public void setNumUsu(int numUsu) {
		this.numUsu = numUsu;
	}
	
	public void IncrementaUsu(){
		numUsu++;
		label.setText("Usuarios Disponibles: " + getNumUsu());
		// Es usado por principal.view.gui.Principal para regresar el contador de instancias
	}

	JPanel panel = new JPanel();
	JLabel label = new JLabel("Da click para crear un Usuario"); 
	JButton button= new JButton("Crear Usuario");
	
    ProxyAuthentication(int usu){
		numUsu = usu;
		panel.setLayout(new GridLayout(0, 1));
		panel.add(button);
		panel.add(label);
		getContentPane().add(panel, BorderLayout.CENTER);
		this.pack();
		this.resize(200, 100);
		this.setResizable(false);
		this.setVisible(true);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//numUsu--;				
				
				if (getNumUsu() >= 1){
					numUsu--;
					label.setText("Usuarios Disponibles: " + getNumUsu());
					LoginManager view = new LoginManager();
					Usuarios user = view.getUser();
					UserAuthenticationDialog userAuthenticationDialog = 
						new UserAuthenticationDialog(view, true);
				}
				else{
					label.setText("No hay mas usuarios");					
				}
			}
		});

		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) { 				
				System.exit(0);
			} 
		}); 
    } 
}